#ifndef _CSDATAANALYSE_H
#define _CSDATAANALYSE_H

#include <string>
using namespace std;

#include "CSGameRecord.h"
#include "CSAnalyse.h"

#include <hash_map>

using namespace std;
using namespace stdext;

__declspec(selectany) const TCHAR *conEvent_Conn			= "connected, address";
__declspec(selectany) const TCHAR *conEvent_Enter			= "entered the game";
__declspec(selectany) const TCHAR *conEvent_Join			= "joined team";
__declspec(selectany) const TCHAR *conEvent_DisConn			= "disconnected";
__declspec(selectany) const TCHAR *conEvent_Kill			= "killed";
__declspec(selectany) const TCHAR *conEvent_PlantBomb		= "Planted_The_Bomb";
__declspec(selectany) const TCHAR *conEvent_BeginDefuse		= "Begin_Bomb_Defuse_Without_Kit";
__declspec(selectany) const TCHAR *conEvent_DefuseBomb		= "Defused_The_Bomb";
__declspec(selectany) const TCHAR *conEvent_RoundStart		= "Round_Start";
__declspec(selectany) const TCHAR *conEvent_RoundEnd		= "Round_End";
__declspec(selectany) const TCHAR *conEvent_TerroristWin	= "Terrorists_Win";
__declspec(selectany) const TCHAR *conEvent_CTWin			= "CTs_Win";
__declspec(selectany) const TCHAR *conEvent_TargetBombed	= "Target_Bombed";
__declspec(selectany) const TCHAR *conEvent_ChangeMap		= "Loading map";
//__declspec(selectany) const TCHAR *conEvent_Dropped			= "Dropped"

#define PLAYERNUM 100

typedef enum{etNONE,
			 etCONNECTED, 
			 etENTERED_THE_GAME, 
			 etJOINED_TEAM, 
			 etDISCONNECTED, 
			 etKILLED, 
			 etPLANTED_THE_BOMB, 
			 etBEGIN_BOMB_DEFUSE_WITHOUT_KIT, 
			 etDEFUSED_THE_BOMB,
			 etROUND_START,
			 etROUND_END,
			 etTERRORISTS_WIN,
			 etCTS_WIN,
			 etTARGET_BOMBED,
			 etCHANGE_MAP}	EVENT_TYPES;

struct CS_PLAYER_INFO
{
	int nCSPlayerID;
	int nRole;
	CS_PLAYER_INFO() : nCSPlayerID(0), nRole(0)
	{
	}
};

typedef struct tagEVENT_DATETIME
{
	string strDate;
	string strTime;
	string strDateTime;
}EVENT_DATETIME;

struct MAPINFO
{
	int nMapID;
	string strMapName;
	MAPINFO() : nMapID(0)
	{}
};

struct PLAYERINFO
{
	CS_PLAYER_INFO cpiCSPlayerInfo;
	int nUserID;
	string strUserName;
	string strIP;
	string strTimeConn;
	PLAYERINFO() : nUserID(0), cpiCSPlayerInfo() 
	{}
};

typedef struct tagTHREAD_FUNC_PARAM
{
	HANDLE hPipeRead;
	MAPINFO mi;
	CCSGameRecord csgr;
	CCSUserInfoBase *pUI;
}THREAD_FUNC_PARAM;

typedef struct tagINDEX_PLAYER_ROLE
{
	int Role[3][PLAYERNUM];
}INDEX_PLAYER_ROLE;

class CCSDataAnalyse
{
public:
	CCSDataAnalyse();
	~CCSDataAnalyse();

public:
	BOOL pick_Event_Types();
	void pick_EventInfo(EVENT_DATETIME *edtEventDateTime, CS_PLAYER_INFO *cpiCSPlayerInfo);
	void pick_EventInfo(EVENT_DATETIME *edtEventDateTime, CS_PLAYER_INFO *cpiCSPlayerInfo, string &strPlayerIP);
	void pick_EventInfo(EVENT_DATETIME *edtEventDateTime, CS_PLAYER_INFO *cpiCSPlayerInfo, int *nJoinedRole);
	void pick_EventInfo(EVENT_DATETIME *edtEventDateTime, CS_PLAYER_INFO *cpiCSPlayerInfo_Killed, CS_PLAYER_INFO *cpiCSPlayerInfo_Be_Killed, string &strWeapon);
	void pick_EventInfo(EVENT_DATETIME *edtEventDateTime, string &strMapName);
	void pick_DateTime(EVENT_DATETIME *edtEventDateTime);

public:
	void put_Event(TCHAR *chEvent);
	EVENT_TYPES get_EventTypes();

private:
	void pick_CSPlayerInfo(const string &strPlayer, CS_PLAYER_INFO *cpiCSPlayerInfo);
	void pick_Weapon(const string &strWith, string &strWeapon);
	void pick_Role(int *nRole);

private:
	EVENT_TYPES m_etEventTypes;
	string m_strEvent;
	//string m_strPosEventKey;
	static const string::size_type npos = -1;
	
private:
	string strPlayerInfo;
	string strPlayerRole;
	string strPlayerIPPort;
	string strKilledPlayer;
	string strBeKilledPlayer;
	string strWeaponName;
	string strMapChange;
};

extern "C"
{
	DWORD WINAPI ReadPipe(THREAD_FUNC_PARAM *tfp);
}

#endif